<!-- 招商合作 -->
<template>
    <div>
        <a-card title="" :bordered="false">
            <div v-if="hasMerchants">
                <merchants-detail :data="merchantsDetailData"></merchants-detail>
            </div>
            <div v-else>
                <add-merchants @saveSuccess="merchantsSaveSuccess"
                               :projectNumber="p.project_number"
                               :projectName="p.name"></add-merchants>
                
            </div>
        
        </a-card>
        <!--         fixed footer toolbar -->
    
    </div>
</template>

<script>

    import FooterToolBar from '@/components/tools/FooterToolBar'
    import indexedDB from '@/db/db'
    import moment from 'moment'
    import AddMerchants from './AddMerchants'
    import MerchantsDetail from './MerchantsDetail'

    export default {
        name: "DevelementPlans",
        components: {
            FooterToolBar,
            AddMerchants,
            MerchantsDetail,
        },
        data() {
            return {
                loading: false,
                form: this.$form.createForm(this),
                //
                dataInit: {
                    test: '123',
                },
                p:[],
                hasMerchants: false,
                merchantsDetailData:{}


            }
        },
        mounted() {
            let id = this.$route.query.objId
            this.getProjectDetail(parseInt(id))
        },
        methods: {
            getProjectDetail(id){
                indexedDB.get({name:'project'}, id).then(res=>{
                    console.log(res)
                    if(res.length > 0){
                        this.p = res[0]
                        this.getMerchants()
                    }

                })
            },
            merchantsSaveSuccess(){
                this.getMerchants()
            },
            getMerchants(){
                let kRound = IDBKeyRange.only(this.p.project_number)
                indexedDB.handleDataByIndex('merchants',kRound,'project_number').then(res=>{
                    if(res.length > 0){
                        this.merchantsDetailData = res[0]
                        let f = this.merchantsDetailData.files
                        for(let key in f){
                            f[key].url = URL.createObjectURL(f[key].originFileObj)
                        }
                        
                        this.hasMerchants = true
                    }

                })
            },


        },
    }
</script>

<style lang="scss" scoped>
    .card {
        margin-bottom: 24px;
    }
    .title {
        font-size: 20px;
        line-height: 28px;
        font-weight: 500;
        color: rgba(0, 0, 0, 0.85);
        margin: 16px 0 30px 0;
    }
</style>